我正在尝试在我的程序中登录Facebook并从那里解析一些信息(如姓名,个人资料图片等).
每次执行下面的代码时,我都会被重定向回Facebook的主页面.
string email = "email";
string pw = "pw";
string PostData = String.Format("email={0}&pass={1}", email, pw);
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("");
req.CookieContainer = cookieContainer;
req.Method = "POST";
req.ContentLength = PostData.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.AllowAutoRedirect = true;
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes(PostData);
req.ContentLength = loginDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
HttpWebResponse webResp = (HttpWebResponse)req.GetResponse();
Stream datastream = webResp.GetResponseStream();
StreamReader …Run Code Online (Sandbox Code Playgroud) 在标准应用程序中,我有以下内容:
[Required]
[DisplayName("Email Address")]
public string EmailAddress { get; set; }
Run Code Online (Sandbox Code Playgroud)
...这反过来会自动生成一个英文表格字段的标签.
现在,如果我需要我的应用程序支持5种语言,那么ASP.NET MVC应用程序处理此问题的最佳方法是什么?
适用范围约为400-600个数据字段.
更新:我还需要支持更新应用程序中的小部分文本,如页面名称和每个表单的引入(小段落).
我想点击链接,我想自己去主页上的页面
<a onclick="javascript:GoToHomePage()" href="javascript:void(0)">Home page</a>
Run Code Online (Sandbox Code Playgroud)
功能是
function GoToHomePage()
{
window.location = 'default.aspx';
}
Run Code Online (Sandbox Code Playgroud)
但我想要网页www.testtest.com的网址而不是www.testtest.com/default.aspx
我甚至无法给出像www.testtest.com这样的绝对路径,因为它是一个门户网站,同一页面会出现在更多的门户网站中.
我正在尝试在UNIX上成功完成的新功能,但不知道如何在Windows上执行操作.
所以我保存了一个文本文件,让我们说test1.txt和12小时后比较test2.txt(这是test1.txt与12小时内添加的更改,几乎保证在文件的末尾)到test1.txt然后将文本差异输出到第三个文件diff.txt
1 action
2 action
3 action
4 action
5 action
Run Code Online (Sandbox Code Playgroud)
和test2.txt看起来像
1 action
2 action
3 action
4 action
5 action
6 action
7 action
8 action
Run Code Online (Sandbox Code Playgroud)
然后输出到第三个文件diff.txt看起来像:
6 action
7 action
8 action
Run Code Online (Sandbox Code Playgroud)
只有已添加的文本,没有关于行或比较的信息,只是差异的基本输出.
我完全是新手,环顾四周,似乎我可以写一个批处理文件(.bat),基本上只是作为UNIX脚本.
对不起我的基本问题,但我搜索了这个问题,似乎无法弄明白.
在主页的页面加载中,我设置了这样的cookie: -
if (abc == true)
{
HttpCookie cookie = new HttpCookie("Administrator");
cookie.Value = "Admin";
cookie.Expires = DateTime.Now.AddDays(-1);
Response.SetCookie(cookie);
}
Run Code Online (Sandbox Code Playgroud)
并使用cookie作为: -
if (Request.Cookies["Administrator"] != null)
{
if (Request.Cookies["Administrator"].Value == "Admin")
//some code
}
Run Code Online (Sandbox Code Playgroud)
注销时我希望此cookie过期或被删除.所以我写了: - Seesion.Abandon();
现在,即使我退出后,当我重新登录主页时,该行Request.Cookies["Administrator"]仍然不是空的.
奇怪...!请告诉我这是什么原因和解决方案.
最近几天我想到了asp.net中的输出缓存.在我的任务中,我需要为这个非常大的项目实现输出缓存.经过几个小时的搜索,我没有找到任何例子.
最流行的使用输出缓存的方式是声明性的,在这种情况下,您需要在要缓存的页面上编写类似这样的内容.
但是,如果您需要缓存整个站点,则必须在项目的所有页面或母版页上编写此文件.这很疯狂.在这种情况下,您无法将所有配置存储在一个位置.所有页面都有自己的配置..
Global.asax可以帮助我,但我的网站包含大约20个web progects和~20个global.asax文件.而且我不想为每个项目复制相同的代码.
出于这些原因,我决定创建HTTPModule.在Init方法中,我订阅了两个事件:
public void Init(HttpApplication app)
{
app.PreRequestHandlerExecute += new EventHandler(OnApplicationPreRequestHandlerExecute);
app.PostRequestHandlerExecute += new EventHandler(OnPostRequestHandlerExecute);
}
Run Code Online (Sandbox Code Playgroud)
在方法"OnPostRequestHandlerExecute"中,我为每个新请求设置输出缓存参数:
public void OnPostRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpCachePolicy policy = app.Response.Cache;
policy.SetCacheability(HttpCacheability.Server);
policy.SetExpires(app.Context.Timestamp.AddSeconds((double)600));
policy.SetMaxAge(new TimeSpan(0, 0, 600));
policy.SetValidUntilExpires(true);
policy.SetLastModified(app.Context.Timestamp);
policy.VaryByParams.IgnoreParams = true;
}
Run Code Online (Sandbox Code Playgroud)
在"OnApplicationPreRequestHandlerExecute"方法中,我将calback方法设置为缓存验证:
public void OnApplicationPreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
app.Context.Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(Validate), app);
}
Run Code Online (Sandbox Code Playgroud)
最后一部分 - 回调验证方法:
public void Validate(HttpContext context, Object data, ref HttpValidationStatus status)
{
if (context.Request.QueryString["id"] == …Run Code Online (Sandbox Code Playgroud) 现在我有一个公式:
int a = 53, x = 53, length = 62, result;
result = (a + x) % length;
Run Code Online (Sandbox Code Playgroud)
但如果我已知结果,如何计算反向模量以获得最小的"x"
(53 + x) % 62 = 44
//how to get x
Run Code Online (Sandbox Code Playgroud)
我的意思是获得x的公式或逻辑是什么
我只是有一个简单的问题,看看自己上课时最好的做法是什么.
假设这个类有一个私有成员在构造函数中初始化,我是否必须检查这个私有成员在另一个公共的非静态方法中是否为null?或者是假设该变量不为null,因此不必添加该检查?
例如,如下所示,检查null是绝对必要的.
// Provides Client connections.
public TcpClient tcpSocket;
/// <summary>
/// Creates a telnet connection to the host and port provided.
/// </summary>
/// <param name="Hostname">The host to connect to. Generally, Localhost to connect to the Network API on the server itself.</param>
/// <param name="Port">Generally 23, for Telnet Connections.</param>
public TelnetConnection(string Hostname, int Port)
{
tcpSocket = new TcpClient(Hostname, Port);
}
/// <summary>
/// Closes the socket and disposes of the TcpClient.
/// </summary>
public void CloseSocket()
{ …Run Code Online (Sandbox Code Playgroud) 我在互联网上找到了一些找到所有href标签并将其更改为google.com的代码,但是如何告诉代码找到所有input字段并将自定义文本放在那里?
这是我现在的代码:
HtmlDocument doc = new HtmlDocument();
doc.Load(path);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
HtmlAttribute att = link.Attributes["href"];
att.Value = "http://www.google.com";
}
doc.Save("file.htm");
Run Code Online (Sandbox Code Playgroud)
请,有人可以帮助我,我似乎无法在互联网上找到任何有关这方面的信息:(.
我试图通过使用类别并覆盖canPerformAction并在复制,剪切和粘贴选择器中返回NO来禁用UIWebView中的复制/粘贴.
当我加载网页或所有其他文档格式(例如docx,pptx,rtf,txt)时,它按预期工作,但在我将PDF文档加载到UIWebView时却没有.
似乎有一些不同的机制在UIWebView中处理PDF文档,它处理/响应复制选择器,因此我无法阻止它.
我还尝试禁用UIWebView的UIScrollView的所有子视图的用户交互,这对于除PDF之外的其他文档格式都可以正常工作.
任何人都可以帮助弄清楚如何在UIWebView中为PDF文档禁用复制?
c# ×5
.net ×2
asp.net ×2
asp.net-mvc ×1
caching ×1
cookies ×1
facebook ×1
formula ×1
html ×1
httpmodule ×1
javascript ×1
jquery ×1
login ×1
math ×1
modulus ×1
multilingual ×1
outputcache ×1
pdf ×1
post ×1
reverse ×1
uiwebview ×1
windows ×1