Serenity: How to set serenity template in .aspx file

Created on 11 Oct 2016  路  5Comments  路  Source: serenity-is/Serenity

Hai,

I have create .aspx file in my serenity project but how can I set the template comes with the aspx page?

Tq..

Most helpful comment

Hi @keringforza,

I don't know why you're creating an .aspx file in Serenity!

As @marcobisio said:

I think you're a little out of the way

But few days I had to link some legacy.aspx forms in Serenity menu, trying speed up a migration. But figured out that the faster way is going straight to sergen and generate all by ground.

If you still interested in how I embeded .aspx files in Serenity. I had create views with iframes, like this:

  1. ~/Modules/Legacy/[MyEntity]/[MyEntity].cshtml
  2. ~/Modules/Legacy/[MyEntity]/[MyEntityPage].cs
  3. ~/Modules/Legacy/[MyEntity]/[MyEntityPageModel].cs
  4. ~/Modules/Legacy/PermissionKeys.cs
  5. File 1.
@model MyProject.web.Legacy.MyEntityPageModel
@{
    ViewData["Title"] = "MyEntity";
    ViewData["PageId"] = "MyEntity";
}

@section Head {
}

<div class="box box-primary">
    <div class="box-header with-border">
        <div class="box-title">MyEntity</div>
        <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                <i class="fa fa-minus"></i>
            </button>
            <button type="button" class="btn btn-box-tool" data-widget="remove">
                <i class="fa fa-times"></i>
            </button>
        </div>
    </div>
    <div class="box-body" style="width:100%; height:100%; text-align: center;">
        <-- here goes the old .aspx reference --/>
        <iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms"
                src=@("http://mylegacyurl.com/MyLegacyForm.aspx)
                style="border: none; width:100%; height:70vh;"></iframe>
    </div>
    <div class="box-footer"></div>
</div>
  • File 2.

``` C#
namespace MyProject.web.Legacy.Pages
{
using Serenity;
using Serenity.Web;
using System.Web.Mvc;

[RoutePrefix("MyEntity"), Route("{action=index}")]
public class MyEntityController : Controller
{
    [PageAuthorize(Legacy.PermissionKeys.MyEntity), HttpGet, Route("~/MyEntity")]
    public ActionResult Index()
    {
        var cachedModel = new MyEntityPageModel()
        {
        };

        return View(MVC.Views.Legacy.MyEntity.MyEntityIndex, cachedModel);
    }
}

}

- File 3.

``` C#
namespace MyProject.web.Legacy
{
    public class MyEntityPageModel
    {
    }
}
  • File 4.

``` C#
namespace MyProject.web.Legacy
{
///


/// This class contains some permission key constants solely for
/// easy access and intellisense purposes.
public class PermissionKeys
{
public const string MyEntity= "MyEntity:Read";
}
}

- 5. Include in mvc.cs this code: 

``` C#
public static class Legacy
{
    public static class MyEntity
    {
        public const string MyEntityIndex = "~/Modules/Legacy/MyEntity/MyEntity.cshtml";
        }
    }
}
  • And finally you can add in your naviagation menu like this:

``` C#
using Serenity.Navigation;
using Administration = MyProject.web.Administration.Pages;
using Legacy = MyProject.web.Legacy.Pages;

[assembly: NavigationLink(1000, "Dashboard", url: "~/", permission: "", icon: "icon-speedometer")]
[assembly: NavigationMenu(2000, "MyModule", icon: "icon-note")]
[assembly: NavigationLink(2100, "MyModule/MyEntity", typeof(Legacy.MyEntityController), icon: "icon-user")]
```

This is not a good approach, since you can do things easily just using Serenity by itself. But if you can't do it now and really need... It's your way...

Let me know if you try this!

Maybe help someone else to messing up the things too! :stuck_out_tongue_winking_eye:

All 5 comments

Hi @keringforza, I think you're a little out of the way: here we are working with MVC and Razor...
Why do you want to add an old web form page to the project?
Sure there as some kind of mix with mvc and aspx, but onestly I think that they aren't the right approach...

Hi @keringforza,

I don't know why you're creating an .aspx file in Serenity!

As @marcobisio said:

I think you're a little out of the way

But few days I had to link some legacy.aspx forms in Serenity menu, trying speed up a migration. But figured out that the faster way is going straight to sergen and generate all by ground.

If you still interested in how I embeded .aspx files in Serenity. I had create views with iframes, like this:

  1. ~/Modules/Legacy/[MyEntity]/[MyEntity].cshtml
  2. ~/Modules/Legacy/[MyEntity]/[MyEntityPage].cs
  3. ~/Modules/Legacy/[MyEntity]/[MyEntityPageModel].cs
  4. ~/Modules/Legacy/PermissionKeys.cs
  5. File 1.
@model MyProject.web.Legacy.MyEntityPageModel
@{
    ViewData["Title"] = "MyEntity";
    ViewData["PageId"] = "MyEntity";
}

@section Head {
}

<div class="box box-primary">
    <div class="box-header with-border">
        <div class="box-title">MyEntity</div>
        <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                <i class="fa fa-minus"></i>
            </button>
            <button type="button" class="btn btn-box-tool" data-widget="remove">
                <i class="fa fa-times"></i>
            </button>
        </div>
    </div>
    <div class="box-body" style="width:100%; height:100%; text-align: center;">
        <-- here goes the old .aspx reference --/>
        <iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms"
                src=@("http://mylegacyurl.com/MyLegacyForm.aspx)
                style="border: none; width:100%; height:70vh;"></iframe>
    </div>
    <div class="box-footer"></div>
</div>
  • File 2.

``` C#
namespace MyProject.web.Legacy.Pages
{
using Serenity;
using Serenity.Web;
using System.Web.Mvc;

[RoutePrefix("MyEntity"), Route("{action=index}")]
public class MyEntityController : Controller
{
    [PageAuthorize(Legacy.PermissionKeys.MyEntity), HttpGet, Route("~/MyEntity")]
    public ActionResult Index()
    {
        var cachedModel = new MyEntityPageModel()
        {
        };

        return View(MVC.Views.Legacy.MyEntity.MyEntityIndex, cachedModel);
    }
}

}

- File 3.

``` C#
namespace MyProject.web.Legacy
{
    public class MyEntityPageModel
    {
    }
}
  • File 4.

``` C#
namespace MyProject.web.Legacy
{
///


/// This class contains some permission key constants solely for
/// easy access and intellisense purposes.
public class PermissionKeys
{
public const string MyEntity= "MyEntity:Read";
}
}

- 5. Include in mvc.cs this code: 

``` C#
public static class Legacy
{
    public static class MyEntity
    {
        public const string MyEntityIndex = "~/Modules/Legacy/MyEntity/MyEntity.cshtml";
        }
    }
}
  • And finally you can add in your naviagation menu like this:

``` C#
using Serenity.Navigation;
using Administration = MyProject.web.Administration.Pages;
using Legacy = MyProject.web.Legacy.Pages;

[assembly: NavigationLink(1000, "Dashboard", url: "~/", permission: "", icon: "icon-speedometer")]
[assembly: NavigationMenu(2000, "MyModule", icon: "icon-note")]
[assembly: NavigationLink(2100, "MyModule/MyEntity", typeof(Legacy.MyEntityController), icon: "icon-user")]
```

This is not a good approach, since you can do things easily just using Serenity by itself. But if you can't do it now and really need... It's your way...

Let me know if you try this!

Maybe help someone else to messing up the things too! :stuck_out_tongue_winking_eye:

.aspx files are not supported, as you'd have to write master pages specific to it, which is a problematic business. I recommend you avoid aspx, or make them as pages that open in a new tab, or as @Hochmah pointed iframe etc.

Zillion tq to @marcobisio @Hochmah and @volkanceylan for the explanation & suggestion.. i'll discuss with my team to decide the best way to solve this issue..

Hye.. actually what my team trying to do is to create UI for certain function in web config. The file is like this:

  • WebConfiguration.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebConfiguration.aspx.cs" Inherits="IMS.WebConfiguration.WebConfiguration" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        Active Directory
        <asp:TextBox ID="txtAD" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="btnSaveAD" runat="server" OnClick="btnSave" Text="Save" />

    </div>
    </form>
</body>
</html>
  • WebConfiguration.aspx.cs
using System;
using System.Web.Configuration;
using System.Configuration;

namespace IMS.WebConfiguration
{
    public partial class WebConfiguration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave(object sender, EventArgs e)
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("/");
            string oldValue = config.AppSettings.Settings["ActiveDirectory"].Value;
            config.AppSettings.Settings["ActiveDirectory"].Value = "{Domain: '" + txtAD.Text + "'}";
            config.Save(ConfigurationSaveMode.Modified);
        }
    }
}
  • WebConfiguration.aspx.designer.cs
namespace IMS.WebConfiguration {


    public partial class WebConfiguration {


        protected global::System.Web.UI.HtmlControls.HtmlForm form1;

        protected global::System.Web.UI.WebControls.TextBox txtAD;

        protected global::System.Web.UI.WebControls.Button btnSaveAD;
    }
}

So can anybody help me how to convert this .aspx to meet the right approach for MVC and Razor. Many thanxs..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ga5tan picture ga5tan  路  3Comments

moostafaa picture moostafaa  路  3Comments

chintankukadiya18 picture chintankukadiya18  路  3Comments

john20xdoe picture john20xdoe  路  3Comments

stepankurdylo picture stepankurdylo  路  3Comments