怎么样\r和\n不同?我认为这与Unix与Windows与Mac有关,但我不确定它们是如何不同的,以及在正则表达式中搜索/匹配的方式.
我正在制作一个应该显示带密码的PDF的应用程序.这是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string filePath = Request.QueryString["filePath"];
if (filePath.ToUpper().EndsWith("PDF"))
{
copyPDF(filePath);
}
}
catch
{
string message = "<script language='Javascript'>alert('File Not Found! Call Records Department for verification. ')</script>";
ScriptManager.RegisterStartupScript(Page, this.GetType(), message, message, false);
}
}
}
public void copyPDF(string filePath)
{
iTextSharp.text.pdf.RandomAccessFileOrArray ra = new iTextSharp.text.pdf.RandomAccessFileOrArray(Server.MapPath(ResolveUrl(filePath)));
if (ra != null)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] password = System.Text.ASCIIEncoding.ASCII.GetBytes("Secretinfo");
iTextSharp.text.pdf.PdfReader thepdfReader = new iTextSharp.text.pdf.PdfReader(ra, password);
int pages = thepdfReader.NumberOfPages; …Run Code Online (Sandbox Code Playgroud) 我有以下代码来验证用户是否有权访问该应用程序.问题是System.Web.HttpContext.Current.User.Identity.Name空的.我检查了.可能是什么问题呢?我的其他应用程序使用相同的代码片段,它在那里工作.为什么会这样?
string username = System.Web.HttpContext.Current.User.Identity.Name;
string str = "SELECT LASTNAME +', '+ FIRSTNAME AS NAME, USER_NAME, DEPARTMENT FROM DBNAME.DBO.TABLENAME WHERE USER_NAME = '" + username + "' ";
SqlCommand cmd = new SqlCommand(str, conn);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (rdr.HasRows == false)
{
Server.Transfer("unauthorized.htm");
}
else
{
while (rdr.Read())
{
name = rdr["NAME"].ToString();
username = rdr["USER_NAME"].ToString();
dept = rdr["DEPARTMENT"].ToString();
}
}
Run Code Online (Sandbox Code Playgroud) 目前,我有这个:
Regex folderRegex = new Regex(@"^.{8})([0-9]+)?[1-9]+([0-9]+)?$");
Run Code Online (Sandbox Code Playgroud)
我需要字符串正好有8位数.没有连字符或字母.我的正则表达式会这样做吗?