You could use the UrlReferrer property of the current request:
Request.UrlReferrer
This will read the Referer HTTP header from the request which may or may not be supplied by the client (user agent).
Roman Pelepei gives smart answers on questions about C# .Net, ASP .Net, WPF and Silverlight programming with examples and source code.
Request.UrlReferrer
public class MultiCultureMvcRouteHandler : MvcRouteHandler { protected override IHttpHandler GetHttpHandler(RequestContext requestContext) { var culture = requestContext.RouteData.Values["culture"].ToString(); var ci = new CultureInfo(culture); Thread.CurrentThread.CurrentUICulture = ci; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name); return base.GetHttpHandler(requestContext); } }
public class SingleCultureMvcRouteHandler : MvcRouteHandler {}
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); foreach (Route r in routes) { if (!(r.RouteHandler is SingleCultureMvcRouteHandler)) { r.RouteHandler = new MultiCultureMvcRouteHandler(); r.Url = "{culture}/" + r.Url; //Adding default culture if (r.Defaults == null) { r.Defaults = new RouteValueDictionary(); } r.Defaults.Add("culture", Culture.ru.ToString()); //Adding constraint for culture param if (r.Constraints == null) { r.Constraints = new RouteValueDictionary(); } r.Constraints.Add("culture", new CultureConstraint(Culture.en.ToString(),
Culture.ru.ToString())); } } }
public class CultureConstraint : IRouteConstraint { private string[] _values; public CultureConstraint(params string[] values) { this._values = values; } public bool Match(HttpContextBase httpContext,Route route,string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { // Get the value called "parameterName" from the // RouteValueDictionary called "value" string value = values[parameterName].ToString(); // Return true is the list of allowed values contains // this value. return _values.Contains(value); } }
public enum Culture { ru = 1, en = 2 }
public ActionResult ChangeCulture(Culture lang, string returnUrl) { if (returnUrl.Length >= 3) { returnUrl = returnUrl.Substring(3); } return Redirect("/" + lang.ToString() + returnUrl); }
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%= Html.ActionLink("eng", "ChangeCulture", "Account", new { lang = (int)MvcLocalization.Helpers.Culture.en, returnUrl = this.Request.RawUrl }, new { @class = "culture-link" })%> <%= Html.ActionLink("рус", "ChangeCulture", "Account", new { lang = (int)MvcLocalization.Helpers.Culture.ru, returnUrl = this.Request.RawUrl }, new { @class = "culture-link" })%>
routes.MapRoute( "AboutRoute", "About", new { controller = "Home", action = "About"} ).RouteHandler = new SingleCultureMvcRouteHandler();
(function( skillet, $, undefined ) {
//Private Property
var isHot = true;
//Public Property
skillet.ingredient = "Bacon Strips";
//Public Method
skillet.fry = function() {
var oliveOil;
addItem( "\t\n Butter \n\t" );
addItem( oliveOil );
console.log( "Frying " + skillet.ingredient );
};
//Private Method
function addItem( item ) {
if ( item !== undefined ) {
console.log( "Adding " + $.trim(item) );
}
}
}( window.skillet = window.skillet || {}, jQuery ));
//Adding New Functionality to the Skillet
(function( skillet, $, undefined ) {
//Private Property
var amountOfGrease = "1 Cup";
//Public Method
skillet.toString = function() {
console.log( skillet.quantity + " " +
skillet.ingredient + " & " +
amountOfGrease + " of Grease" );
console.log( isHot ? "Hot" : "Cold" );
};
}( window.skillet = window.skillet || {}, jQuery ));
protected override void Seed (EntityContext context)
{
if (!WebSecurity.Initialized)
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
if (!Roles.RoleExists("Administrator"))
Roles.CreateRole("Administrator");
if (!WebSecurity.UserExists("Owner"))
WebSecurity.CreateUserAndAccount("Owner", "password");
if (!Roles.GetRolesForUser("Owner").Contains("Administrator"))
Roles.AddUsersToRoles(new[] { "Owner" }, new[] { "Administrator" });
if (!WebSecurity.UserExists("fred"))
WebSecurity.CreateUserAndAccount("leemid", "pw");
if (!Roles.GetRolesForUser("leemid").Contains("Administrator"))
Roles.AddUsersToRoles(new[] { "leemid" }, new[] { "Administrator" });
base.Seed(context);
}
<system.web>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<clear/>
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
</providers>
</roleManager>
<membership defaultProvider="SimpleMembershipProvider">
<clear/>
<add name="SimpleMembershipProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>