如何在asp.net mvc中成功登录后在网址中显示用户名?

时间:2016-02-26 07:06:40

标签: asp.net-mvc

我正在创建一个电子商务网站。我想在登录后为用户动态设置用户名。我的代码:

namespace EcommerceDbFirstApproch.Models
{
    public class ExampleRoute : Route
    {
        public ExampleRoute(string url) : base(url, new MvcRouteHandler()) { }

        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var url = httpContext.Request.Headers["HOST"];
            var index = url.IndexOf(".");

            if (index < 0)
                return null;

            var subDomain = url.Substring(0, index);

            if (subDomain == CookieHelper.GetCookieValue(CookieKeys.UserName))
            {
                var routeData = new RouteData(this, new MvcRouteHandler());
                routeData.Values.Add("controller", "Product"); //Goes to the User1Controller class
                routeData.Values.Add("action", "Index"); //Goes to the Index action on the User1Controller

                return routeData;
            }

            return null;
        }       
    }
}

它不起作用。我错过了什么吗?

示例 - admin.localhost / Product / Index

动态登录后我想要这种类型的Url。

0 个答案:

没有答案