我正在尝试使用客户端IP地址
HttpContext.Request.UserHostAddress;
Run Code Online (Sandbox Code Playgroud)
但它回来了::1.
怎么解决这个?
怎么做?
我不想用这个:
HttpContext.Current.Server.MapPath
Run Code Online (Sandbox Code Playgroud)
是否有一个类似的功能,我可以调用,而不需要httpcontext?
例如,如果一个线程做一些东西我不能使用httpcontext,但我仍然需要获取应用程序的路径.并且我不能将上下文作为参数传递或从共享var中读取它.
我在Application_Start上生成一个线程,并希望记录异常.没有Context/HttpContext/HttpContext.Current,所以我怎么能让它登录?
目前,它没有捕获我的线程中的任何异常,如果我写,ErrorSignal.FromCurrentContext().Raise(ex);我得到一个关于上下文的错误不能为空.
也许我可以创建一个虚拟的HttpContext但不知何故我认为这不会很好.
-edit-我试过ErrorSignal.Get(new HttpApplication()).Raise(ex);,它似乎没有拿起那个例外.
我有一个在所有应用程序中使用的值; 我在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) 我有一个Silverlight应用程序(使用MVC),当我在Visual Studio中构建时,使用Visual Studio开发中心,没有问题,它HttpContext.Current.User.Identity.Name有一个价值
但是当我在IIS 7.5中使用相同的项目时(我正在使用Windows 7),HttpContext.Current.User.Identity.Name保持空白
有谁可以提供帮助?或者知道我在哪里可以从visual studio开发中心找到设置,所以我可以检查IIS中有什么问题?
我一直试图让.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) 我在纯WCF上下文中运行了一些RESTful服务(即没有启用ASP.NET兼容性,因此没有HttpContext.Current可用的对象).
服务的URL在请求开始时使用IHttpModule(在此时确实具有HttpContext并使用其重写HttpContext.Current.RewritePath)来重写,以.svc从URL中删除诸如扩展之类的内容.
但是,我需要访问WCF基础结构中请求的原始URL.是否有一个相当于HttpContext.Current.Request.RawUrl上OperationContext或WebOperationContext类哪儿了吗?使用WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri返回重写的URL而不是原始的URL.
wcf url-rewriting httpcontext operationcontext weboperationcontext
我有一个本地应用程序有一个路径:
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://)
只是不想冒任何机会.所以问这个愚蠢的问题.
我想使用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"选项.
这不一定是一个问题,我只是好奇它是如何工作的.我有一个方法:
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如果用户不存在,但它是如何知道哪些用户名存在或不存在?
httpcontext ×10
c# ×7
asp.net ×6
iis ×3
asp.net-mvc ×2
http ×2
.net-4.5 ×1
asp.net-4.5 ×1
elmah ×1
exception ×1
ip ×1
outputstream ×1
wcf ×1