标签: httpcontext

返回结果":: 1"的Request.UserHostAddress问题

我正在尝试使用客户端IP地址

    HttpContext.Request.UserHostAddress;
Run Code Online (Sandbox Code Playgroud)

但它回来了::1.

怎么解决这个?

c# ip asp.net-mvc httpcontext

50
推荐指数
2
解决办法
3万
查看次数

不使用httpcontext获取应用程序路径.(asp.net)

怎么做?

我不想用这个:

HttpContext.Current.Server.MapPath
Run Code Online (Sandbox Code Playgroud)

是否有一个类似的功能,我可以调用,而不需要httpcontext?

例如,如果一个线程做一些东西我不能使用httpcontext,但我仍然需要获取应用程序的路径.并且我不能将上下文作为参数传递或从共享var中读取它.

asp.net iis http httpcontext

49
推荐指数
2
解决办法
2万
查看次数

elmah:没有HttpContext的例外?

我在Application_Start上生成一个线程,并希望记录异常.没有Context/HttpContext/HttpContext.Current,所以我怎么能让它登录?

目前,它没有捕获我的线程中的任何异常,如果我写,ErrorSignal.FromCurrentContext().Raise(ex);我得到一个关于上下文的错误不能为空.

也许我可以创建一个虚拟的HttpContext但不知何故我认为这不会很好.

-edit-我试过ErrorSignal.Get(new HttpApplication()).Raise(ex);,它似乎没有拿起那个例外.

c# asp.net elmah exception httpcontext

42
推荐指数
1
解决办法
1万
查看次数

为什么HttpContext.Current为null?

我有一个在所有应用程序中使用的值; 我在application_start中设置了它

  void Application_Start(object sender, EventArgs e)
  {
    Dictionary<int, IList<string>> Panels = new Dictionary<int, IList<string>>();
    List<clsPanelSetting> setting = clsPanelSettingFactory.GetAll();
    foreach (clsPanelSetting panel in setting)
    {
        Panels.Add(panel.AdminId, new List<string>() { panel.Phone,panel.UserName,panel.Password});
    }
    Application["Setting"] = Panels;

    SmsSchedule we = new SmsSchedule();
    we.Run();

  }
Run Code Online (Sandbox Code Playgroud)

并在SmsSchedule

public class SmsSchedule : ISchedule
{
    public void Run()
    {           
        DateTimeOffset startTime = DateBuilder.FutureDate(2, IntervalUnit.Second);
        IJobDetail job = JobBuilder.Create<SmsJob>()
            .WithIdentity("job1")
            .Build();

        ITrigger trigger = TriggerBuilder.Create()
             .WithIdentity("trigger1")
             .StartAt(startTime)
             .WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever())
             .Build();

        ISchedulerFactory sf = new StdSchedulerFactory();
        IScheduler sc …
Run Code Online (Sandbox Code Playgroud)

c# asp.net iis httpcontext

42
推荐指数
3
解决办法
9万
查看次数

HttpContext.Current.User.Identity.Name为Empty

我有一个Silverlight应用程序(使用MVC),当我在Visual Studio中构建时,使用Visual Studio开发中心,没有问题,它HttpContext.Current.User.Identity.Name有一个价值

但是当我在IIS 7.5中使用相同的项目时(我正在使用Windows 7),HttpContext.Current.User.Identity.Name保持空白

有谁可以提供帮助?或者知道我在哪里可以从visual studio开发中心找到设置,所以我可以检查IIS中有什么问题?

iis httpcontext visual-studio

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

使用HttpContext OutputStream写入ZipArchive

我一直试图让.NET 4.5(System.IO.Compression.ZipArchive)中包含的"新"ZipArchive 在ASP.NET站点中工作.但似乎它不喜欢写入流HttpContext.Response.OutputStream.

我的下面的代码示例将抛出

System.NotSupportedException:不支持指定的方法

只要在流上尝试写入.

CanWrite流上的属性返回true.

如果我将OutputStream与文件流交换,指向本地目录,它就可以工作.是什么赋予了?

ZipArchive archive = new ZipArchive(HttpContext.Response.OutputStream, ZipArchiveMode.Create, false);

ZipArchiveEntry entry = archive.CreateEntry("filename");

using (StreamWriter writer = new StreamWriter(entry.Open()))
{
    writer.WriteLine("Information about this package.");
    writer.WriteLine("========================");
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

[NotSupportedException: Specified method is not supported.]
System.Web.HttpResponseStream.get_Position() +29
System.IO.Compression.ZipArchiveEntry.WriteLocalFileHeader(Boolean isEmptyFile) +389
System.IO.Compression.DirectToArchiveWriterStream.Write(Byte[] buffer, Int32 offset, Int32 count) +94
System.IO.Compression.WrappedStream.Write(Byte[] buffer, Int32 offset, Int32 count) +41
Run Code Online (Sandbox Code Playgroud)

c# outputstream httpcontext .net-4.5 asp.net-4.5

36
推荐指数
3
解决办法
1万
查看次数

什么是WCF相当于HttpContext.Current.Request.RawUrl?

我在纯WCF上下文中运行了一些RESTful服务(即没有启用ASP.NET兼容性,因此没有HttpContext.Current可用的对象).

服务的URL在请求开始时使用IHttpModule(在此时确实具有HttpContext并使用其重写HttpContext.Current.RewritePath)来重写,以.svc从URL中删除诸如扩展之类的内容.

但是,我需要访问WCF基础结构中请求的原始URL.是否有一个相当于HttpContext.Current.Request.RawUrlOperationContextWebOperationContext类哪儿了吗?使用WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri返回重写的URL而不是原始的URL.

wcf url-rewriting httpcontext operationcontext weboperationcontext

34
推荐指数
1
解决办法
3万
查看次数

HttpContext.Current.Request.Url.Host它返回什么?

我有一个本地应用程序有一个路径:

http://localhost:950/m/pages/Searchresults.aspx?search=knife&filter=kitchen
Run Code Online (Sandbox Code Playgroud)

但是当它进入集成环境或生产时,它就会像

http://www.someshopping.com/m/pages/SearchResults.aspx?search=knife&filter=kitchen
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我需要通过:

www.someshopping.com
Run Code Online (Sandbox Code Playgroud)

到我的XSLT文件和我正在使用的函数之一:

string currentURL = HttpContext.Current.Request.Url.Host;
Run Code Online (Sandbox Code Playgroud)

这会在本地环境中返回" localhost ".相同的代码会回复我:

www.someshopping.com在制作中(我不需要http://)

只是不想冒任何机会.所以问这个愚蠢的问题.

c# asp.net http httpcontext

34
推荐指数
3
解决办法
10万
查看次数

HttpContext.Current没有在MVC 4项目中解析

我想使用ImageResizer(来自ImageResizing dot net).我通过NuGet为MVC安装了ImageResizer.但是当我从示例中使用以下代码时:

//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
{
    HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
    if (file.ContentLength <= 0) continue; //Skip unused file controls.

    //The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
    //Destination paths can have variables like <guid> and <ext>, or 
    //even a santizied version of the original filename, like <filename:A-Za-z0-9>
    ImageResizer.ImageJob i = new ImageResizer.ImageJob(file, "~/uploads/<guid>.<ext>", new ImageResizer.ResizeSettings(
                            "width=2000;height=2000;format=jpg;mode=max"));
    i.CreateParentDirectory = true; //Auto-create the uploads directory.
    i.Build();
}
Run Code Online (Sandbox Code Playgroud)

foreach中的"HttpContext.Current.Request.Files.Keys"是不是正在解决?我的用法正确,Visual Studio不提供"Resolve"选项.

c# asp.net asp.net-mvc httpcontext asp.net-mvc-4

34
推荐指数
2
解决办法
4万
查看次数

HttpContext.Current.User.Identity.Name如何知道存在哪些用户名?

这不一定是一个问题,我只是好奇它是如何工作的.我有一个方法:

public static bool UserIsAuthenticated()
{
    bool isAuthed = false;
    try
    {
        if (HttpContext.Current.User.Identity.Name != null)
        {
            if (HttpContext.Current.User.Identity.Name.Length != 0)
            {
                FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
                FormsAuthenticationTicket ticket = id.Ticket;
                isAuthed = true;
                string MyUserData = ticket.UserData;
            }
        }
    }
    catch { } // not authed
    return isAuthed;
}
Run Code Online (Sandbox Code Playgroud)

HttpContext.Current.User.Identity.Name返回null如果用户不存在,但它是如何知道哪些用户名存在或不存在?

c# asp.net httpcontext

34
推荐指数
4
解决办法
11万
查看次数