Например: < /p>
Код: Выделить всё
https://localhost:44329/Account/EventPreview?preview=4175
< /code>
- мой текущий запрос. < /p>
https://localhost:44329/Home
< /code>
После добавления строки запроса она должна быть < /p>
https://localhost:44329/Home?preview=4175
< /code>
и аналогично < /p>
https://localhost:44329/Account/CreatePassword?Id=21 =>
https://localhost:44329/Account/CreatePassword?Id=21&preview=4175
Код: Выделить всё
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
int preview = HtmlHelperExtensions.GetIntSessionValue(SessionKey.Preview.ToString());
if (preview > 0)
{
string longurl = $"{filterContext.HttpContext.Request.Scheme}://{filterContext.HttpContext.Request.Host}{filterContext.HttpContext.Request.PathBase}{filterContext.HttpContext.Request.Path}{filterContext.HttpContext.Request.QueryString}";
var uriBuilder = new UriBuilder(longurl);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query.Add("preview", preview.ToString());
uriBuilder.Query = query.ToString();
longurl = uriBuilder.ToString();
if (!filterContext.HttpContext.Request.QueryString.HasValue || (filterContext.HttpContext.Request.QueryString.HasValue && !filterContext.HttpContext.Request.QueryString.Value.Contains("preview")))
{
filterContext.Result = new RedirectResult(longurl);
}
}
}
Код: Выделить всё
app.Use(async (context, next) =>
{
var url = context.Request.GetEncodedUrl();
//// Rewrite privacy URL to index
if (context.Request.QueryString.HasValue)
{
if (string.IsNullOrEmpty(context.Request.Query["preview"]))
{
//context.Request.Query["preview"] = "4175";
context.Request.QueryString.Add(QueryString.Create("preview", "4175"));
}
}
else
{
context.Request.QueryString.Add(QueryString.Create("preview", "4175"));
}
//context.Request.Path = "";
await next();
});
protected void Application_BeginRequest(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
HttpContext context = base.Context;
#region ForQueryStringPrevent
var oHttpApplication = (HttpApplication)sender;
var oPathAndQuery = oHttpApplication.Context.Request.Url.PathAndQuery;
if (oPathAndQuery.Contains("?" + HtmlHelperExtension.Encrypt("Alliant=")))
{
var NewoPathAndQuery = oPathAndQuery.Split(new string[] { "?" }, StringSplitOptions.None);
var oPath = NewoPathAndQuery[0];
var oQueryString = NewoPathAndQuery[1].Replace(HtmlHelperExtension.Encrypt("Alliant="), "");
var oDecodedURL = HtmlHelperExtension.Decrypt(oQueryString.ToString());
oHttpApplication.Context.RewritePath(oPath + "?" + oDecodedURL.ToString());
}
#endregion
}
< /code>
Может ли кто -нибудь помочь мне с этим? Есть ли способ добавить строку запроса, как и в приложении ASP.NET MVC?
Подробнее здесь: https://stackoverflow.com/questions/689 ... n-net-core