相关疑难解决方法(0)

如何在ASP.NET MVC中模拟Server.Transfer?

在ASP.NET MVC中,您可以非常轻松地返回重定向ActionResult:

 return RedirectToAction("Index");

 or

 return RedirectToRoute(new { controller = "home", version = Math.Random() * 10 });
Run Code Online (Sandbox Code Playgroud)

这实际上会提供HTTP重定向,这通常很好.但是,当使用谷歌分析时,这会导致很大的问题,因为最初的引用会丢失,所以谷歌不知道你来自哪里.这会丢失有用的信息,例如任何搜索引擎术语.

作为旁注,此方法的优点是可以删除任何可能来自广告系列但仍允许我捕获服务器端的参数.将它们留在查询字符串中会导致人们加入书签或推特或博客链接,而这些链接不应该存在.我已经多次看到这样的情况,人们在我们的网站上链接了包含广告系列ID的链接.

无论如何,我正在为网站的所有传入访问写一个"网关"控制器,我可能会重定向到不同的地方或替代版本.

现在我更关心谷歌(比意外的书签),我希望能够发送访问/该页面的人,如果他们去了/home/7,这是主页的第7版.

就像我之前说的如果我这样做,我失去了谷歌分析引用者的能力:

 return RedirectToAction(new { controller = "home", version = 7 });
Run Code Online (Sandbox Code Playgroud)

我真正想要的是一个

 return ServerTransferAction(new { controller = "home", version = 7 });
Run Code Online (Sandbox Code Playgroud)

这将使我看到没有客户端重定向的视图.我不认为这样的事情存在.

目前我能想到的最好的事情是HomeController.Index(..)在我的GatewayController.IndexAction中复制整个控制器逻辑.这意味着我必须'Views/Home'进入,'Shared'因此它是可访问的.肯定有更好的办法??..

asp.net-mvc server.transfer

123
推荐指数
8
解决办法
7万
查看次数

ELMAH - 使用自定义错误页面收集用户反馈

我正在寻找第一次使用ELMAH,但是需要满足我不确定如何实现的要求......

基本上,我将配置ELMAH在asp.net MVC下工作,并让它在发生错误时将错误记录到数据库中.除此之外,我将使用customErrors在发生错误时将用户定向到友好的消息页面.相当标准的东西......

要求是在这个自定义错误页面上我有一个表单,使用户可以根据需要提供额外的信息.现在问题出现的原因是此时已经记录了错误,我需要将漏洞错误与用户反馈相关联.

通常,如果我使用自己的自定义实现,在记录错误后,我会将错误的ID传递给自定义错误页面,以便可以建立关联.但由于ELMAH的工作方式,我不认为这是可能的.

因此我想知道人们怎么会想到这样做......

干杯

更新:

我对这个问题的解决方案如下:

public class UserCurrentConextUsingWebContext : IUserCurrentConext
{
    private const string _StoredExceptionName = "System.StoredException.";
    private const string _StoredExceptionIdName = "System.StoredExceptionId.";

    public virtual string UniqueAddress
    {
        get { return HttpContext.Current.Request.UserHostAddress; }
    }

    public Exception StoredException
    {
        get { return HttpContext.Current.Application[_StoredExceptionName + this.UniqueAddress] as Exception; }
        set { HttpContext.Current.Application[_StoredExceptionName + this.UniqueAddress] = value; }
    }

    public string StoredExceptionId
    {
        get { return HttpContext.Current.Application[_StoredExceptionIdName + this.UniqueAddress] as string; }
        set { HttpContext.Current.Application[_StoredExceptionIdName + this.UniqueAddress] = value; …
Run Code Online (Sandbox Code Playgroud)

error-handling asp.net-mvc elmah custom-error-pages

8
推荐指数
1
解决办法
3239
查看次数